﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


namespace IT_Pro.Class
{
    class NV_CodeDienThoai
    {
        private int _idcode;

        public int Idcode
        {
            get { return _idcode; }
            set { _idcode = value; }
        }
        private string _manv;

        public string Manv
        {
            get { return _manv; }
            set { _manv = value; }
        }
        private DateTime _ngaycap;

        public DateTime Ngaycap
        {
            get { return _ngaycap; }
            set { _ngaycap = value; }
        }
        private DateTime _ngayhuy;

        public DateTime Ngayhuy
        {
            get { return _ngayhuy; }
            set { _ngayhuy = value; }
        }
        private int _loaicode;

        public int Loaicode
        {
            get { return _loaicode; }
            set { _loaicode = value; }
        }
        private string _lan1;

        public string Lan1
        {
            get { return _lan1; }
            set { _lan1 = value; }
        }
        private string _lan2;

        public string Lan2
        {
            get { return _lan2; }
            set { _lan2 = value; }
        }
        private string _lan3;

        public string Lan3
        {
            get { return _lan3; }
            set { _lan3 = value; }
        }
        private string _lan4;

        public string Lan4
        {
            get { return _lan4; }
            set { _lan4 = value; }
        }
        private string _lan5;

        public string Lan5
        {
            get { return _lan5; }
            set { _lan5 = value; }
        }

        private DateTime _ngayLan2;

        public DateTime NgayLan2
        {
            get { return _ngayLan2; }
            set { _ngayLan2 = value; }
        }
        private DateTime _ngayLan3;

        public DateTime NgayLan3
        {
            get { return _ngayLan3; }
            set { _ngayLan3 = value; }
        }
        private DateTime _ngayLan4;

        public DateTime NgayLan4
        {
            get { return _ngayLan4; }
            set { _ngayLan4 = value; }
        }
        private DateTime _ngayLan5;

        public DateTime NgayLan5
        {
            get { return _ngayLan5; }
            set { _ngayLan5 = value; }
        }

        public static DataTable HienThiCodeNhanVien(string manv)
        {
            string strSQL = "select * from NV_CodeDienThoai code,NV_LoaiCode lcode where code.LoaiCode=lcode.MaLoai and MaNV='"+manv+"'";
            return DataServices.ExecQuery(strSQL);
        }
        public static bool ThemCodevaCapNhat(NV_CodeDienThoai _code,int _sosanh)
        {
            string sql="";
            if (_sosanh == 1)
            {
                sql = "insert into NV_CodeDienThoai(MaNV,NgayCap,LoaiCode,CapLan1,CapLan2,CapLan3,CapLan4,CapLan5) values ('" + _code.Manv + "','" + _code.Ngaycap + "','" + _code.Loaicode + "','" + _code.Lan1 + "','" + _code.Lan2 + "','" + _code.Lan3 + "','" + _code.Lan4 + "','" + _code.Lan5 + "')";
            }
            else
            {
                if (_code.NgayLan2 != DateTime.Parse("1/1/0001 12:00:00AM"))
                {
                    sql = "update NV_CodeDienThoai Set CapLan1='" + _code.Lan1 + "',CapLan2='" + _code.Lan2 + "',CapLan3='" + _code.Lan3 + "',CapLan4='" + _code.Lan4 + "',CapLan5='" + _code.Lan5 + "',NgayLan2='" + _code.NgayLan2+"' ";
                    if (_code.NgayLan3 != DateTime.Parse("1/1/0001 12:00:00AM"))
                    {
                        sql+=",NgayLan3='" + _code.NgayLan3+"' ";
                    }
                    if (_code.NgayLan4 != DateTime.Parse("1/1/0001 12:00:00AM"))
                    {
                        sql += ",NgayLan4='" + _code.NgayLan4 + "' ";
                    }
                    if (_code.NgayLan5 != DateTime.Parse("1/1/0001 12:00:00AM"))
                    {
                        sql += ",NgayLan5='" + _code.NgayLan5 + "' ";
                    }
                }
                
                
                sql+="where MaNV='" + _code.Manv + "'";
            }
            DataServices.ExecNonQuery(sql);
            return true;
        }
    }   
    class NV_LoaiCodeDienThoai
    {
        public static DataTable HienThiDsLoaiCode()
        {
            string strSQL = "select * from NV_LoaiCode";
            return DataServices.ExecQuery(strSQL);
        }     
    }
}
